﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace System.Peppers.Wmi
{
    /// <summary>
    /// Base class for accounts
    /// </summary>
    public class Account : CimSetting
    {
        #region Static
        private static class WmiProperties
        {
            public const string LocalAccount = "LocalAccount",
                SID = "SID",
                SIDType = "SIDType";
        }
        #endregion

        internal Account(ManagementObject wmiObject)
            : base(wmiObject)
        { }

        /// <summary>
        /// If True, the account is defined on the local computer.
        /// </summary>
        public bool LocalAccount
        {
            get { return Convert.ToBoolean(this[WmiProperties.LocalAccount] ?? false); }
        }

        /// <summary>
        /// Security identifier (SID) for this account. A SID is a string value of variable length that is used to identify a trustee. Each account has a unique SID that an authority, such as a Windows domain, issues. The SID is stored in the security database. When a user logs on, the system retrieves the user SID from the database, places the SID in the user access token, and then uses the SID in the user access token to identify the user in all subsequent interactions with Windows security. Each SID is a unique identifier for a user or group, and a different user or group cannot have the same SID.
        /// </summary>
        public string SID
        {
            get { return Convert.ToString(this[WmiProperties.SID]); }
        }

        /// <summary>
        /// Enumerated value that specifies the type of SID.
        /// </summary>
        public AccountSIDType SIDType
        {
            get { return (AccountSIDType)Convert.ToByte(this[WmiProperties.SIDType] ?? 0); }
        }
    }
}
